/**
 * 
 */
package UsedCar;

import org.apache.commons.lang.StringUtils;

/**
 * @author August F.Y. Chao
 * 
 */
public class Post {

	/**
	 * @param POST_TYPE_QUESTION
	 *            問題
	 * @param POST_TYPE_ARTICLE
	 *            文章
	 */
	public static final int POST_TYPE_QUESTION = 0, POST_TYPE_ARTICLE = 1;

	/**
	 * @param postType
	 *            文章型式
	 */
	int postType = 0;
	/**
	 * @param postKnows
	 *            文章內容
	 */
	String[] postKnows;
	/**
	 * @param postQuality
	 *            文章品質
	 */
	float postQuality = 0;
	/**
	 * @param owner
	 *            發文人
	 */
	Agent owner;
	/**
	 * @param replyTo
	 *            回應的文章
	 */
	Post replyTo;
	/**
	 * @param 被回應的文章
	 */
	Post[] replyFrm;
	/**
	 * @param insertYr
	 *            插入時間
	 */
	int insertYr = 0;
	/**
	 * @param influSeller
	 *            產生正向影響的店家 in Seller.sellerString()
	 */
	String influSeller = "";

	/**
	 * @param influV
	 *            影響值
	 */
	int influV = 1;

	public int getInfluV() {
		return influV;
	}

	public void setInfluV(int influV) {
		this.influV = influV;
	}

	/**
	 * @param post_id
	 *            發文的序號
	 */
	int post_id = 0;

	/**
	 * @param yr
	 *            目前的年
	 */
	public int yr;

	/**
	 * @param beforeYr
	 *            被重設之前的年
	 */
	public int beforeYr;

	/**
	 * 一篇文章的內容
	 * 
	 * @param owner
	 *            文章的所有人
	 * @param knows
	 *            文章的知識
	 * @param postQuality
	 *            文章品質
	 * @param postType
	 *            文章型態
	 */
	public Post(Agent owner, String[] knows, float postQuality, int postType) {
		this.setPostType(postType);
		this.setPostKnows(knows);
		this.setPostQuality(postQuality);
		this.setOwner(owner);
	}

	/**
	 * 重設文章
	 * 
	 * @param nYr
	 *            重設到指定年
	 */
	public void resetYr(int nYr) {
		if (insertYr != nYr) {

			this.beforeYr = this.insertYr;
			this.insertYr = nYr;
		}
	}

	/**
	 * 列出本文的內容
	 */
	public void show() {
		String foo = "";
		foo += "Owner: " + this.owner.getRole() + " (X,Y): "
				+ this.owner.getMyX() + "," + this.owner.getMyY()
				+ " post_id: " + post_id + "\n";
		foo += "Knows: " + StringUtils.join(this.getPostKnows(), " | ") + "\n";
		foo += "Quality: " + this.getPostQuality() + "\n";
		foo += "Type: " + this.getPostType() + "\n";
		foo += "Year: " + insertYr + " beforeYr:" + this.beforeYr + "\n";
		foo += "Influ Seller: " + influSeller + "\n";
		foo += "Influ Value: " + influV + "\n";
		System.out.println(foo);
	}

	/**
	 * 加上本文對賣家的影響
	 * 
	 * @param sellerStr
	 *            賣家字串 sellerString()
	 */
	public void addInflu(String sellerStr) {
		setInfluSeller(sellerStr);
	}

	// ---------------------------------------------------------------------------------------------------------------------------------------------//
	// 變數的 setter and getter
	// ---------------------------------------------------------------------------------------------------------------------------------------------//
	public int getPostType() {
		return postType;
	}

	public void setPostType(int postType) {
		this.postType = postType;
	}

	public String[] getPostKnows() {
		if (postKnows.length > 0) {
			return postKnows;
		}
		return new String[0];
	}

	public void setPostKnows(String[] postKnows) {
		this.postKnows = postKnows;
	}

	public float getPostQuality() {
		return postQuality;
	}

	public void setPostQuality(float postQuality) {
		this.postQuality = postQuality;
	}

	public Post getReplyTo() {
		return replyTo;
	}

	public void setReplyTo(Post replyTo) {
		this.replyTo = replyTo;
	}

	public Post[] getReplyFrm() {
		return replyFrm;
	}

	public void setReplyFrm(Post[] replyFrm) {
		this.replyFrm = replyFrm;
	}

	public Agent getOwner() {
		return owner;
	}

	public void setOwner(Agent owner) {
		this.owner = owner;
	}

	/**
	 * @return 取得影響的賣家
	 */
	public String getInfluSeller() {
		return influSeller;
	}

	public void setInfluSeller(String influSeller) {
		this.influSeller = influSeller;
	}

	public int getPost_id() {
		return post_id;
	}

	public void setPost_id(int post_id) {
		this.post_id = post_id;
	}
}
